import requests
import json
import urllib

sess = requests.Session()
headers = {
    "accept": "*/*",
    "accept-encoding": "gzip, deflate, br",
    "accept-language": "zh-CN,zh;q=0.9",
    "cookie": "__mgjuuid=5fc3e0a4-ef0e-4610-a3d7-c67562277618; _mwp_h5_token_enc=7ece78f2aef386af4285a04d82f7b985; _mwp_h5_token=cfd33fdf1b8af7918fcc70f746144526_1575181846757",
    "referer": "https://list.mogu.com/search/goods?q=%E8%A1%AC%E8%A1%A3&from=querytip0&ptp=31.v5mL0b.0.0.sX10RnsX",
    "sec-fetch-mode": "no-cors",
    "sec-fetch-site": "same-site",
    "user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36",
}
# headers={'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1062.0 Safari/536.3', 'cookie': '__mgjuuid=2bb1dc2f-223b-4322-a64f-93d7b23fcec1'}
data = {
    "pid": "133798",
    "callback": "httpCb157495369271454",
    "_": "1574953692714",
}
dic_data = {"page": 1, "pageSize": 24, "sort": "pop", "ratio": "3:4", "cKey": "pc-search-wall",
            "q": "%E8%A1%AC%E8%A1%A3", "from": "querytip0", "ptp": "31.v5mL0b.0.0.auWtOczJ"}
json_data = json.dumps(dic_data)
formdata = {
    'data': json_data,
    "mw-ckey": "pc-search-wall",
    "mw-appkey": "100028",
    "mw-ttid": "NMMain@mgj_pc_1.0",
    "mw-t": "1575039016530",
    "mw-uuid": "185edc4a-dcf1-47bb-b2cf-8a0f9aebfa15",
    "mw-h5-os": "unknown",
    "mw-sign": "22ca33752c2e5b53e5b5954446575bd3",
    "callback": "mwpCb2",
    "_": "1575039016531",
}
url = 'https://api.mogu.com/h5/mwp.pagani.search/19/?'
json_dd = json.dumps(formdata)
quote_params = urllib.parse.urlencode(formdata)
params = quote_params.replace('+', '')
url = url + params

html = sess.get(url, headers=headers)
print(html.text)
